﻿Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D
Imports Commander_Wars.Spieletools
Public Class ObjektNumericUpDown
    Inherits Objekt2D

    Const ReglerBreite As Integer = 16
    Const Schnellerzaehler As Single = 0.5
    Const MaxGeschwindigkeit As Integer = 10
    Const FramenMax As Integer = 12
    Dim Value As Integer
    Public ReadOnly Property GetValue() As Integer
        Get
            If Value <= Infinite Then
                Return -1
            Else
                Return Value
            End If
        End Get
    End Property
    Public Sub SetValue(ByVal Wert As Integer)
        Value = Wert
        If Value > Max Then Value = Max
        If Value < Min Then Value = Min
        If Value <= Infinite Then
            Text.neuerText(New String() {"∞"}, 2, 1, Nothing)
        Else
            Text.neuerText(New String() {Value}, 2, 1, Nothing)
        End If
    End Sub
    Public Sub SetMaximum(ByVal Wert As Integer)
        Max = Wert
        If Value > Max Then Value = Max
        If Value < Min Then Value = Min
        If Value <= Infinite Then
            Text.neuerText(New String() {"∞"}, 2, 1, Nothing)
        Else
            Text.neuerText(New String() {Value}, 2, 1, Nothing)
        End If
    End Sub
    Public Sub SetMinimum(ByVal Wert As Integer)
        Min = Wert
        If Value > Max Then Value = Max
        If Value < Min Then Value = Min
        If Value <= Infinite Then
            Text.neuerText(New String() {"∞"}, 2, 1, Nothing)
        Else
            Text.neuerText(New String() {Value}, 2, 1, Nothing)
        End If
    End Sub
    Dim Aktiv As Boolean = False
    Dim Zaehlgeschwindigkeit As Double = 0.5
    Dim Min As Integer
    Dim Max As Integer
    Dim Text As ObjektText
    Dim Aenderung As Integer
    Dim Ausgewaeht As Boolean
    Dim Infinite As Integer = -1
    Private Framens As Integer
    Public Property Framen() As Integer
        Get
            Return Framens
        End Get
        Set(ByVal value As Integer)
            Framens += 1
            If Framens > FramenMax Then Framens = 0
        End Set
    End Property
    ''' <summary>
    ''' 0 bedeutet der Text wird ganz am Anfang eingefuegt 1 bedeutet nach dem ersten Buchstaben.
    ''' </summary>
    ''' <remarks></remarks>
    Dim Cursorposition As Integer = 0
    Dim Buchstabenbreite As Integer = 0
    Dim Frame2 As Integer = 0
    Public Sub New(ByVal Startvalue As Integer, ByVal Startmin As Integer, ByVal Startmax As Integer, ByVal Bild As String, ByVal Position As Point, ByVal neueAenderung As Integer, ByVal Fixed As PointF, Optional ByVal Infinite As Integer = -1, Optional ByVal Handler As ObjektPanel = Nothing)
        Me.New(Startvalue, Startmin, Startmax, Image.FromFile(Bild), Position, neueAenderung, Bild, Fixed, Infinite, Handler)
    End Sub
    Public Sub New(ByVal Startvalue As Integer, ByVal Startmin As Integer, ByVal Startmax As Integer, ByVal Bild As Bitmap, ByVal Position As Point, ByVal neueAenderung As Integer, ByVal Bildname As String, ByVal Fixed As PointF, Optional ByVal Infinite As Integer = -1, Optional ByVal Handler As ObjektPanel = Nothing)
        MyBase.New(Bildname, New Rectangle(0, 0, Bild.Width, Bild.Height), Position, Fixed, Nothing)
        Value = Startvalue
        Min = Startmin
        Max = Startmax
        Me.Infinite = Infinite
        Aenderung = neueAenderung
        If Startvalue < Min Then
            Value = Min
        End If
        If Value <= Infinite Then
            Text = New ObjektText(New String() {"∞"}, 2, 1, Nothing, Schriftengine.Schriftarten.Arial, 14, FontStyle.Regular)
        Else
            Text = New ObjektText(New String() {Value.ToString}, 2, 1, Nothing, Schriftengine.Schriftarten.Arial, 14, FontStyle.Regular)
        End If
        Grafikengine.Sprite.Transform = Matrix.Identity
        Dim TxtSize As Size = Text.GetSchriftart.MeasureString(Grafikengine.Sprite, Max.ToString, DrawTextFormat.None, Color.Black).Size
        Bildgroesse = New Rectangle(0, 0, TxtSize.Width + 4, 20)
        Buchstabenbreite = TxtSize.Width / Max.ToString.Length
        'Da Groessen und andere Dinge erst noch berechnet wurden!
        Me.Handler = Handler
        If Me.Handler IsNot Nothing Then
            Me.Handler.AddObjekt(Me)
        End If
    End Sub
    Public Overrides Sub Malen()
        If Handler IsNot Nothing Then
            If Not Handler.IsVisible(New Rectangle(Koordinaten.X, Koordinaten.Y, Rechteck.Width + 16, Rechteck.Height), True) Then
                Exit Sub
            End If
        End If
        Dim sngRotation As Double = 0
        Dim intColor As Color = Color.FromArgb(255, 255, 255, 255)
        Grafikengine.ptfRotCenter = Nothing
        Grafikengine.szfScale = Nothing
        Grafikengine.ptfPosition = GetRealKoordinaten()
        With Grafikengine.recBild
            .X = 0 : .Width = 2
            .Y = 0 : .Height = 20
        End With
        Grafikengine.Sprite.Draw2D(Textur.getTextur(TexturID), Grafikengine.recBild, Grafikengine.szfScale, Grafikengine.ptfRotCenter, sngRotation, Grafikengine.ptfPosition, intColor)
        Text.Malen(Grafikengine.ptfPosition)
        Grafikengine.ptfPosition.X += Rechteck.Width + 15
        Grafikengine.recBild.X = 30
        Grafikengine.Sprite.Draw2D(Textur.getTextur(TexturID), Grafikengine.recBild, Grafikengine.szfScale, Grafikengine.ptfRotCenter, sngRotation, Grafikengine.ptfPosition, intColor)
        Grafikengine.ptfPosition.X = GetRealX() + 2
        With Grafikengine.recBild
            .X = 2 : .Width = 13
            .Y = 0 : .Height = 20
        End With
        Grafikengine.szfScale.Width = Rechteck.Width
        Grafikengine.szfScale.Height = 20
        Grafikengine.Sprite.Draw2D(Textur.getTextur(TexturID), Grafikengine.recBild, Grafikengine.szfScale, Grafikengine.ptfRotCenter, sngRotation, Grafikengine.ptfPosition, intColor)
        With Grafikengine.recBild
            .X = 16 : .Width = 14
            .Y = 0 : .Height = 20
        End With
        Grafikengine.szfScale = Nothing
        Grafikengine.ptfPosition.X = GetRealX() + 1 + Rechteck.Width
        Grafikengine.Sprite.Draw2D(Textur.getTextur(TexturID), Grafikengine.recBild, Grafikengine.szfScale, Grafikengine.ptfRotCenter, sngRotation, Grafikengine.ptfPosition, intColor)
        If Focused Then
            'Wir muessen jetzt diesen | malen
            Frame2 += 1
            If Frame2 > 11 Then Frame2 = 0
            If Frame2 < 6 Then
                Dim Pos As Integer = Cursorposition
                Grafikengine.fillRect(New Rectangle(Pos * Buchstabenbreite + 2 + GetRealX(), +2 + GetRealY(), 1, 17), Color.Black)
            End If
        End If
        'wir lassen den Zaehler immer schneller werden.=)
        If Max >= 0 Then
            If Aktiv = True Then
                If Framen = 0 Then
                    If Zaehlgeschwindigkeit > 0 Then
                        Zaehlgeschwindigkeit += Schnellerzaehler
                        If Zaehlgeschwindigkeit > MaxGeschwindigkeit Then Zaehlgeschwindigkeit = MaxGeschwindigkeit
                    Else
                        Zaehlgeschwindigkeit -= Schnellerzaehler
                        If Zaehlgeschwindigkeit < -MaxGeschwindigkeit Then Zaehlgeschwindigkeit = -MaxGeschwindigkeit
                    End If
                    Dim Aenderung2 As Integer = Round(Zaehlgeschwindigkeit * Aenderung, Aenderung)
                    If Aenderung2 = 0 Then
                        If Zaehlgeschwindigkeit > 0 Then
                            Aenderung2 = Aenderung
                        Else
                            Aenderung2 = -Aenderung
                        End If
                    End If
                    Value += Aenderung2
                    If Value > Max Then Value = Max
                    If Value < Min Then Value = Min
                    If Value <= Infinite Then
                        Text.neuerText(New String() {"∞"}, 2, 1, Nothing)
                    Else
                        Text.neuerText(New String() {Value}, 2, 1, Nothing)
                    End If
                End If
                Framen = 1
            End If
        End If
        NextFrame()
    End Sub
    Public Overrides Function Keydown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) As Boolean
        If IsVisble() Then
            If Me.Focused Then
                Select Case e.KeyCode
                    Case Keys.Enter
                        Me.RemoveFocus()
                    Case Keys.Back
                        'Wenn was geloescht wird dann nur wenn was zu loeschen da ist
                        If Cursorposition > 0 Then
                            'Wir wollen was loeschen.
                            Dim Val As String = Value.ToString.Remove(Cursorposition - 1, 1)
                            If Val <> "" Then
                                SetValue(Val)
                            Else
                                SetValue(Min)
                            End If
                            Cursorposition -= 1
                        End If
                    Case Keys.Left
                        If Cursorposition > 0 Then Cursorposition -= 1
                    Case Keys.Right
                        If Cursorposition < Value.ToString.Length Then Cursorposition += 1
                    Case Keys.Delete
                        If Cursorposition < Value.ToString.Length Then
                            Dim Val As String = Value.ToString.Remove(Cursorposition, 1)
                            If Val <> "" Then
                                SetValue(Val)
                            Else
                                SetValue(Min)
                            End If
                        End If

                End Select
            End If
        End If
    End Function

    ''' <summary>
    ''' Uebergibt den Text an diese Textbox
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub NextFrame()
        If Focused Then
            Hauptmenue.ChatboxLocker.Lock()
            Dim Text As String = Hauptmenue.MainMenue.txtChatbox.Text
            If IsNumeric(Text) Then
                Dim Laenge As Integer = Text.Length
                If Laenge > 0 Then
                    Dim CurVal As String = Value.ToString
                    CurVal = CurVal.Insert(Cursorposition, Text)
                    Hauptmenue.MainMenue.txtChatbox.Text = ""
                    Cursorposition += Laenge
                    Dim NewVAl As Integer = CInt(CurVal)
                    If NewVAl > Max Then
                        SetValue(Max)
                    ElseIf NewVAl < Min Then
                        SetValue(Min)
                    Else
                        SetValue(NewVAl)
                    End If
                End If
            ElseIf (Text = "-") And Cursorposition = 0 Then
                Dim Laenge As Integer = Text.Length
                If Laenge > 0 Then
                    Dim CurVal As String = Value.ToString
                    CurVal = CurVal.Insert(Cursorposition, Text)
                    Hauptmenue.MainMenue.txtChatbox.Text = ""
                    Cursorposition += Laenge
                    Dim NewVAl As Integer = CInt(CurVal)
                    If NewVAl > Max Then
                        SetValue(Max)
                    ElseIf NewVAl < Min Then
                        SetValue(Min)
                    Else
                        SetValue(NewVAl)
                    End If
                End If
            End If
            Hauptmenue.ChatboxLocker.Unlock()
            If Cursorposition > Value.ToString.Length Then
                Cursorposition = Value.ToString.Length
            End If
        End If
    End Sub

    Public Overrides Function KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) As Boolean

    End Function

    Public Overloads Overrides Function MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As Boolean
        If IsVisble(16) Then
            If (Not HasFocus) Or Focused Then
                Dim P As Point = GetRealKoordinaten()
                Dim StartRechteck As New Rectangle(P.X + Rechteck.Width, P.Y, ReglerBreite, 6)
                If Rechteck.Contains(e.X, e.Y) Then
                Else
                    If StartRechteck.Contains(e.X, e.Y) Then
                        Aktiv = True
                        If Value <= Infinite Then
                            Text.neuerText(New String() {"∞"}, 2, 1, Nothing)
                        Else
                            Text.neuerText(New String() {Value}, 2, 1, Nothing)
                        End If
                        Return True
                    Else
                        StartRechteck.Y += 10
                        If StartRechteck.Contains(e.X, e.Y) Then
                            Aktiv = True
                            Zaehlgeschwindigkeit = -0.5#
                            If Value <= Infinite Then
                                Text.neuerText(New String() {"∞"}, 2, 1, Nothing)
                            Else
                                Text.neuerText(New String() {Value}, 2, 1, Nothing)
                            End If
                            Return True
                        Else
                            StartRechteck = New Rectangle(P.X + 2, P.Y, Rechteck.Width, Rechteck.Height)
                            If StartRechteck.Contains(e.X, e.Y) Then
                                Focus()
                                Hauptmenue.MainMenue.txtChatbox.Text = ""
                                Hauptmenue.MainMenue.txtChatbox.Focus()
                                Dim X As Integer = e.X - P.X
                                Cursorposition = Math.DivRem(X, Buchstabenbreite, 0)
                                If Cursorposition > Value.ToString.Length Then
                                    Cursorposition = Value.ToString.Length
                                End If
                                Return True
                            Else

                                Me.RemoveFocus()
                            End If
                        End If
                    End If
                End If
                Return False
            End If
        End If
        Return False
    End Function


    Public Overloads Overrides Function MouseEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As Boolean

    End Function

    Public Overloads Overrides Function MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As String
        Aktiv = False
        Zaehlgeschwindigkeit = 0.5
        Framens = 0
        Return ""
    End Function


    Public Overloads Overrides Function MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As Boolean

    End Function

    Public Overrides Sub RemoveFocus()
        If Focused Then
            Hauptmenue.MainMenue.Focus()
            MyBase.RemoveFocus()
        End If
    End Sub
End Class

Public Class ObjektTimeUpDown
    Inherits Objekt2D

    Const ReglerBreite As Integer = 16
    Const Schnellerzaehler As Long = 3
    Const MaxGeschwindigkeit As Integer = 30
    Const FramenMax As Integer = 6
    Dim Value As Long
    Public ReadOnly Property GetValue() As Long
        Get
            If Value <= Infinite Then
                Return -1
            Else
                Return Value
            End If
        End Get
    End Property
    Public Sub SetValue(ByVal Wert As Long)
        Value = Wert
        If Value > Max Then Value = Max
        If Value < Min Then Value = Min
        CreateText
    End Sub
    Public Sub SetMaximum(ByVal Wert As Long)
        Max = Wert
        If Value > Max Then Value = Max
        If Value < Min Then Value = Min
       CreateText
    End Sub
    Public Sub SetMinimum(ByVal Wert As Long)
        Min = Wert
        If Value > Max Then Value = Max
        If Value < Min Then Value = Min
       CreateText
    End Sub
    Dim Aktiv As Int16 = 0
    Dim Zaehlgeschwindigkeit As Long = -2
    Dim Min As Long
    Dim Max As Long
    Dim Text As ObjektText
    Dim Aenderung As Long
    Dim Ausgewaeht As Boolean
    Dim Infinite As Integer = -1
    Private Framens As Integer
    Public Property Framen() As Integer
        Get
            Return Framens
        End Get
        Set(ByVal value As Integer)
            Framens += 1
            If Framens > FramenMax Then Framens = 0
        End Set
    End Property
    ''' <summary>
    ''' 0 bedeutet der Text wird ganz am Anfang eingefuegt 1 bedeutet nach dem ersten Buchstaben.
    ''' </summary>
    ''' <remarks></remarks>
    Dim Cursorposition As Integer = 0
    Dim Buchstabenbreite As Integer = 0
    Dim Frame2 As Integer = 0
    Public Sub New(ByVal Startvalue As Long, ByVal Startmin As Long, ByVal Startmax As Long, ByVal Bild As String, ByVal Position As Point, ByVal neueAenderung As Long, ByVal Fixed As PointF, Optional ByVal Infinite As Integer = -1, Optional ByVal Handler As ObjektPanel = Nothing)
        Me.New(Startvalue, Startmin, Startmax, Image.FromFile(Bild), Position, neueAenderung, Bild, Fixed, Infinite, Handler)
    End Sub
    Public Sub New(ByVal Startvalue As Long, ByVal Startmin As Long, ByVal Startmax As Long, ByVal Bild As Bitmap, ByVal Position As Point, ByVal neueAenderung As Long, ByVal Bildname As String, ByVal Fixed As PointF, Optional ByVal Infinite As Integer = -1, Optional ByVal Handler As ObjektPanel = Nothing)
        MyBase.New(Bildname, New Rectangle(0, 0, Bild.Width, Bild.Height), Position, Fixed, Nothing)
        Value = Startvalue
        Min = Startmin
        Max = Startmax
        Me.Infinite = Infinite
        Aenderung = neueAenderung
        If Startvalue < Min Then
            Value = Min
        End If
        Text = New ObjektText(New String() {"∞"}, 2, 1, Nothing, Schriftengine.Schriftarten.Courier_New, 14, FontStyle.Regular)
        CreateText()
        Grafikengine.Sprite.Transform = Matrix.Identity
        Dim TxtSize As Size = Text.GetSchriftart.MeasureString(Grafikengine.Sprite, Max.ToString, DrawTextFormat.None, Color.Black).Size
        Bildgroesse = New Rectangle(0, 0, TxtSize.Width + 4, 20)
        Buchstabenbreite = TxtSize.Width / Max.ToString.Length
        'Da Groessen und andere Dinge erst noch berechnet wurden!
        Me.Handler = Handler
        If Me.Handler IsNot Nothing Then
            Me.Handler.AddObjekt(Me)
        End If
    End Sub
    Public Overrides Sub Malen()
        If Handler IsNot Nothing Then
            If Not Handler.IsVisible(New Rectangle(Koordinaten.X, Koordinaten.Y, Rechteck.Width + 16, Rechteck.Height), True) Then
                Exit Sub
            End If
        End If
        Dim sngRotation As Double = 0
        Dim intColor As Color = Color.FromArgb(255, 255, 255, 255)
        Grafikengine.ptfRotCenter = Nothing
        Grafikengine.szfScale = Nothing
        Grafikengine.ptfPosition = GetRealKoordinaten()
        With Grafikengine.recBild
            .X = 0 : .Width = 2
            .Y = 0 : .Height = 20
        End With
        Grafikengine.Sprite.Draw2D(Textur.getTextur(TexturID), Grafikengine.recBild, Grafikengine.szfScale, Grafikengine.ptfRotCenter, sngRotation, Grafikengine.ptfPosition, intColor)
        Text.Malen(Grafikengine.ptfPosition)
        Grafikengine.ptfPosition.X += Rechteck.Width + 15
        Grafikengine.recBild.X = 30
        Grafikengine.Sprite.Draw2D(Textur.getTextur(TexturID), Grafikengine.recBild, Grafikengine.szfScale, Grafikengine.ptfRotCenter, sngRotation, Grafikengine.ptfPosition, intColor)
        Grafikengine.ptfPosition.X = GetRealX() + 2
        With Grafikengine.recBild
            .X = 2 : .Width = 13
            .Y = 0 : .Height = 20
        End With
        Grafikengine.szfScale.Width = Rechteck.Width
        Grafikengine.szfScale.Height = 20
        Grafikengine.Sprite.Draw2D(Textur.getTextur(TexturID), Grafikengine.recBild, Grafikengine.szfScale, Grafikengine.ptfRotCenter, sngRotation, Grafikengine.ptfPosition, intColor)
        With Grafikengine.recBild
            .X = 16 : .Width = 14
            .Y = 0 : .Height = 20
        End With
        Grafikengine.szfScale = Nothing
        Grafikengine.ptfPosition.X = GetRealX() + 1 + Rechteck.Width
        Grafikengine.Sprite.Draw2D(Textur.getTextur(TexturID), Grafikengine.recBild, Grafikengine.szfScale, Grafikengine.ptfRotCenter, sngRotation, Grafikengine.ptfPosition, intColor)
        If Focused Then
            'Wir muessen jetzt diesen | malen
            Frame2 += 1
            If Frame2 > 11 Then Frame2 = 0
            If Frame2 < 6 Then
                Dim Pos As Integer = Cursorposition
                Grafikengine.fillRect(New Rectangle(Pos * Buchstabenbreite + 2 + GetRealX(), +2 + GetRealY(), 1, 17), Color.Black)
            End If
        End If
        'wir lassen den Zaehler immer schneller werden.=)
        If Max >= 0 Then
            If Aktiv <> 0 Then
                If Framen = 0 Then
                    If Aktiv > 0 Then
                        Zaehlgeschwindigkeit += Schnellerzaehler
                        If Zaehlgeschwindigkeit > MaxGeschwindigkeit Then Zaehlgeschwindigkeit = MaxGeschwindigkeit
                    Else
                        Zaehlgeschwindigkeit -= Schnellerzaehler
                        If Zaehlgeschwindigkeit < -MaxGeschwindigkeit Then Zaehlgeschwindigkeit = -MaxGeschwindigkeit
                    End If
                    Dim Aenderung2 As Long = Round(Zaehlgeschwindigkeit * Aenderung, Aenderung)
                    If Aenderung2 = 0 Then
                        If Zaehlgeschwindigkeit > 0 Then
                            Aenderung2 = Aenderung
                        Else
                            Aenderung2 = -Aenderung
                        End If
                    End If
                    Value += Aenderung2
                    If Value > Max Then Value = Max
                    If Value < Min Then Value = Min
                    CreateText()
                End If
                Framen = 1
            End If
        End If
        NextFrame()
    End Sub
    Private Sub CreateText()
        If Value <= Infinite Then
            Text.neuerText(New String() {"∞"}, 2, 1, Nothing)
        Else
            Dim TimeSpa As TimeSpan = TimeSpan.FromTicks(Value)
            Dim H As Integer = TimeSpa.Hours + 24 * TimeSpa.Days
            Dim Min As Integer = TimeSpa.Minutes
            Dim Sec As Integer = TimeSpa.Seconds
            If H > 0 Then
                If Min > 9 Then
                    If Sec > 9 Then
                        Text.neuerText(New String() {H.ToString + ":" + Min.ToString + ":" + Sec.ToString}, 2, 1, Nothing)
                    Else
                        Text.neuerText(New String() {H.ToString + ":" + Min.ToString + ":0" + Sec.ToString}, 2, 1, Nothing)
                    End If
                Else
                    If Sec > 9 Then
                        Text.neuerText(New String() {H.ToString + ":0" + Min.ToString + ":" + Sec.ToString}, 2, 1, Nothing)
                    Else
                        Text.neuerText(New String() {H.ToString + ":0" + Min.ToString + ":0" + Sec.ToString}, 2, 1, Nothing)
                    End If
                End If
            Else
                If Min > 9 Then
                    If Sec > 9 Then
                        Text.neuerText(New String() {Min.ToString + ":" + Sec.ToString}, 2, 1, Nothing)
                    Else
                        Text.neuerText(New String() {Min.ToString + ":0" + Sec.ToString}, 2, 1, Nothing)
                    End If
                Else
                    If Sec > 9 Then
                        Text.neuerText(New String() {"0" + Min.ToString + ":" + Sec.ToString}, 2, 1, Nothing)
                    Else
                        Text.neuerText(New String() {"0" + Min.ToString + ":0" + Sec.ToString}, 2, 1, Nothing)
                    End If
                End If
            End If

        End If

    End Sub
    Public Overrides Function Keydown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) As Boolean
        If IsVisble() Then
            If Me.Focused Then
                Select Case e.KeyCode
                    Case Keys.Enter
                        Me.RemoveFocus()
                    Case Keys.Back
                        'Wenn was geloescht wird dann nur wenn was zu loeschen da ist
                        If Cursorposition > 0 Then
                            'Wir wollen was loeschen.
                            Dim Val As String = Me.Text.Text(0).Remove(Cursorposition - 1, 1)
                            If Val <> "" Then
                                Dim V As Long = 0
                                Dim S() As String = Val.Split(":")
                                If S.Length > 0 Then
                                    If S.Length > 1 Then
                                        If S.Length > 2 Then
                                            V = CLng(S(2)) * TimeSpan.TicksPerSecond + CLng(S(1)) * TimeSpan.TicksPerMinute + CLng(S(0)) * TimeSpan.TicksPerHour
                                        Else
                                            V = CLng(S(1)) * TimeSpan.TicksPerSecond + CLng(S(0)) * TimeSpan.TicksPerMinute
                                        End If
                                    Else
                                        V = CLng(S(0)) * TimeSpan.TicksPerSecond
                                    End If
                                Else
                                    V = 0
                                End If
                                SetValue(V)
                            Else
                                SetValue(Min)
                            End If
                            Cursorposition -= 1
                        End If
                    Case Keys.Left
                        If Cursorposition > 0 Then Cursorposition -= 1
                    Case Keys.Right
                        If Cursorposition < Text.Text(0).ToString.Length Then Cursorposition += 1
                    Case Keys.Delete
                        If Cursorposition < Value.ToString.Length Then
                            Dim Val As String = Value.ToString.Remove(Cursorposition, 1)
                            If Val <> "" Then
                                Dim V As Long = 0
                                Dim S() As String = Val.Split(":")
                                If S.Length > 0 Then
                                    If S.Length > 1 Then
                                        If S.Length > 2 Then
                                            V = CLng(S(2)) * TimeSpan.TicksPerSecond + CLng(S(1)) * TimeSpan.TicksPerMinute + CLng(S(0)) * TimeSpan.TicksPerHour
                                        Else
                                            V = CLng(S(1)) * TimeSpan.TicksPerSecond + CLng(S(0)) * TimeSpan.TicksPerMinute
                                        End If
                                    Else
                                        V = CLng(S(0)) * TimeSpan.TicksPerSecond
                                    End If
                                Else
                                    V = 0
                                End If
                                SetValue(V)
                            Else
                                SetValue(Min)
                            End If
                        End If
                End Select
            End If
        End If
    End Function

    ''' <summary>
    ''' Uebergibt den Text an diese Textbox
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub NextFrame()
        If Focused Then
            Hauptmenue.ChatboxLocker.Lock()
            Dim Text As String = Hauptmenue.MainMenue.txtChatbox.Text
            If IsNumeric(Text) Then
                Dim Laenge As Integer = Text.Length
                If Laenge > 0 Then
                    Dim CurVal As String = Me.Text.Text(0)
                    CurVal = CurVal.Remove(Cursorposition, 1)
                    CurVal = CurVal.Insert(Cursorposition, Text)
                    Hauptmenue.MainMenue.txtChatbox.Text = ""
                    Dim V As Long = 0
                    Dim S() As String = CurVal.Split(":")
                    If S.Length > 0 Then
                        If S.Length > 1 Then
                            If S.Length > 2 Then
                                V = CLng(S(2)) * TimeSpan.TicksPerSecond + CLng(S(1)) * TimeSpan.TicksPerMinute + CLng(S(0)) * TimeSpan.TicksPerHour
                            Else
                                V = CLng(S(1)) * TimeSpan.TicksPerSecond + CLng(S(0)) * TimeSpan.TicksPerMinute
                            End If
                        Else
                            V = CLng(S(0)) * TimeSpan.TicksPerSecond
                        End If
                    Else
                        V = 0
                    End If
                    SetValue(V)
                End If
            End If
            Hauptmenue.ChatboxLocker.Unlock()
            If Cursorposition > Value.ToString.Length Then
                Cursorposition = Value.ToString.Length
            End If
        End If
    End Sub

    Public Overrides Function KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) As Boolean

    End Function

    Public Overloads Overrides Function MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As Boolean
        If IsVisble(16) Then
            If (Not HasFocus) Or Focused Then
                Dim P As Point = GetRealKoordinaten()
                Dim StartRechteck As New Rectangle(P.X + Rechteck.Width, P.Y, ReglerBreite, 6)
                If Rechteck.Contains(e.X, e.Y) Then
                Else
                    If StartRechteck.Contains(e.X, e.Y) Then
                        Aktiv = 1
                        Zaehlgeschwindigkeit = -2
                        CreateText()
                        Return True
                    Else
                        StartRechteck.Y += 10
                        If StartRechteck.Contains(e.X, e.Y) Then
                            Aktiv = -1
                            Zaehlgeschwindigkeit = 2
                            CreateText
                            Return True
                        Else
                            StartRechteck = New Rectangle(P.X + 2, P.Y, Rechteck.Width, Rechteck.Height)
                            If StartRechteck.Contains(e.X, e.Y) Then
                                Focus()
                                Hauptmenue.MainMenue.txtChatbox.Text = ""
                                Hauptmenue.MainMenue.txtChatbox.Focus()
                                Dim X As Integer = e.X - P.X
                                Cursorposition = Math.DivRem(X, Buchstabenbreite, 0)
                                If Cursorposition > Text.Text(0).ToString.Length Then
                                    Cursorposition = Text.Text(0).ToString.Length
                                End If
                                Return True
                            Else

                                Me.RemoveFocus()
                            End If
                        End If
                    End If
                End If
                Return False
            End If
        End If
        Return False
    End Function


    Public Overloads Overrides Function MouseEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As Boolean

    End Function

    Public Overloads Overrides Function MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As String
        Aktiv = 0
        Zaehlgeschwindigkeit = -2
        Framens = 0
        Return ""
    End Function


    Public Overloads Overrides Function MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As Boolean

    End Function

    Public Overrides Sub RemoveFocus()
        If Focused Then
            Hauptmenue.MainMenue.Focus()
            MyBase.RemoveFocus()
        End If
    End Sub
End Class
